import org.junit.Test;

import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 描述  :
 * 创建人:    Wzy
 * 创建时间: 2020-06-11  3:24
 */
public class Demo1 {
    @Test
    public void test() {
        int sum = getDouble(a -> 2 + a);
        System.out.println(sum);
    }

    private int getDouble(Function<Integer, Integer> function) {
        int num = 1;
        for (int i = 1; i <= 2; i++) {
            num += i;
        }
        return function.apply(num);
    }

    @Test
    public void test2() {
        Random random = new Random();
        List<Integer> collect = Stream.generate(() -> (int) (Math.random() * 10)).limit(4).collect(Collectors.toList());
        System.out.println(collect);
    }

    private static final Random RANDOM = new Random();

    @Test
    public void test4() {

        for (int i = 0; i < 20; i++) {
            Optional<String> reduce = Stream.generate(() -> RANDOM.nextInt(10)).map(String::valueOf).limit(6).reduce((a, b) -> a + b);
            System.out.println(reduce.orElse("123456"));
        }

    }
}
